package ie.timalb.chess.main.ui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class Board {

	JFrame chessFrame;
	JPanel chessPanelTop, chessPanelMiddle, chessPanelBottom, chessPanelLeft, chessPanelRight;
	JButton[] squares, leftRight, topBottom;
	
	public Board()
	{
	}
	
	public void createBoard()
    {
		System.out.println("in createBoard method");
		createFrame();
		createPanels();
		createSquares();
		addSquares();
		addPanels();
		
		Container contentPane = chessFrame.getContentPane();
        contentPane.add(chessPanelTop);
        contentPane.add(chessPanelMiddle);
        chessFrame.setVisible(true);	
		
    }
	
	public void createFrame()
	{
		System.out.println("in createFrame method");
		chessFrame = new JFrame();
		chessFrame.setTitle("Chess");
		chessFrame.setBounds(0, 0, 1000, 900);
		
		//chessFrame.getContentPane.add(sq1);
	}
	public void createPanels()
	{
		System.out.println("in createPanels method");
		chessPanelTop = new JPanel();
  	  	chessPanelMiddle = new JPanel();
  	  	chessPanelBottom = new JPanel();
  	  	chessPanelLeft = new JPanel();
	  	chessPanelRight = new JPanel();
        chessFrame.setLayout(new BorderLayout());
        chessPanelMiddle.setLayout(new GridLayout(8,8));            
	}
	
	public void createSquares()
	{
		System.out.println("in createSquares method");
		squares = new JButton[64];
		for(int i = 0; i < 64; i++)
		{
			if(i%2 == 0)
			{
				// Add alernate images for the different squares here - brown/white etc
				squares[i] = new JButton(String.valueOf(i), new ImageIcon("C:\\Java\\Chess\\images\\white.gif"));
				//"Square" + 
			}
			else
			{
				squares[i] = new JButton(String.valueOf(i), new ImageIcon("C:\\Java\\Chess\\images\\black.gif"));
			}
			
		}
		
		//Create the outer squares (A - H, 1, 8)
		leftRight = new JButton[8];
		for(int i = 0; i < 8; i++)
		{
			leftRight[i] = new JButton(new ImageIcon("C:\\Java\\Chess\\images\\leftRight[i].gif"));
		}
		
		topBottom = new JButton[8];
		for(int i = 0; i < 8; i++)
		{
			topBottom[i] = new JButton(String.valueOf(i), new ImageIcon("C:\\Java\\Chess\\images\\topBottom[i].gif"));
		}
		
	}
	
	public void addSquares()
	{
		System.out.println("in addSquares method");
		for(int i = 0; i < 64; i++)
		{
			chessPanelMiddle.add(squares[i]);
		}
		//chessPanelMiddle.add(sq1);
	}
	
	public void addPanels()
	{
		System.out.println("in addPanels method");
		chessFrame.add(chessPanelTop);
		chessFrame.add(chessPanelMiddle);
	}		
}
